package com.cbj.db_work.controller;


import com.cbj.db_work.common.result.R;
import com.cbj.db_work.entity.Player;
import com.cbj.db_work.entity.PlayerData;
import com.cbj.db_work.entity.vo.PlayDataVo;
import com.cbj.db_work.service.PlayerDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cbj
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/db_work/player-data")
@CrossOrigin
public class PlayerDataController {
    @Autowired
    private PlayerDataService dataService;
    @PostMapping("/setData")
    public R setData(@RequestBody PlayDataVo playDataVo){
        boolean flag = dataService.saveData(playDataVo);
        if(flag)
            return R.ok();
        return R.error();
    }
    @GetMapping("/getData/{id}")
    public R getData(@PathVariable String id){
        List<Integer> list = dataService.getData(id);
        if(list!=null)
            return R.ok().data("data",list);
        return R.error();
    }
    @GetMapping("/rank/{factor}")
    public R rank(@PathVariable String factor){
        Map map = dataService.rank(factor);
        return R.ok().data(map);
    }
}

